<template>
  <div>
    <van-nav-bar title="我的关注" left-arrow @click-left="onClickLeft" />
    <div class="list" v-for="(item, index) in list" :key="index">
      <div class="box">
        <img :src="item.head_img | joinPath" alt="" />
        <div class="center">
          <p>{{ item.nickname }}</p>
          <span>{{ item.create_date ? item.create_date : new date() }}</span>
        </div>
        <span @click="followFn(item.id)">取消关注</span>
      </div>
    </div>
  </div>
</template>

<script>
import { userAttention, userUnfollows } from "@/apis/get.js";
export default {
  data() {
    return {
      list: [],
    };
  },
  created() {
    userAttention().then((res) => {
      // console.log(res);
      this.list = res.data.data;
    });
  },
  methods: {
    // 取消关注
    followFn(id) {
      // 已关注，点击取消关注
      // console.log(34);
      this.followToggle(userUnfollows, id, "取消关注成功");
    },
    // 取消关注函数封装
    followToggle(backFn, id, val) {
      backFn(id).then((res) => {
        // console.log(79, res);
        if (res.data.message == val) {
          this.$toast(res.data.message);
          userAttention().then((res) => {
            // console.log(res);
            this.list = res.data.data;
          });
        }
      });
    },
    // 返回个人中心
    onClickLeft() {
      this.$router.push({
        path: "personal",
      });
    },
  },
};
</script>

<style lang="less" scoped>
.list {
  .box {
    display: flex;
    padding: 25px 10px;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #ccc;
    > img {
      display: block;
      width: 50/360 * 100vw;
      height: 50/360 * 100vw;
      border-radius: 50%;
      padding: 0 10px;
    }
    > .center {
      flex: 1;
      > p {
        line-height: 30px;
        font-size: 14px;
      }
      > span {
        font-size: 12px;
        color: #999;
      }
    }
    > span {
      height: 30px;
      background-color: #eee;
      font-size: 13px;
      border-radius: 30px;
      line-height: 30px;
      padding: 0px 15px;
    }
  }
}
</style>